package com.joney.backstage.config;
import com.joney.backstage.interceptor.AuthInterceptor;
import com.joney.common.config.WebConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;

/**
* @author wangxianchen
* @create 2018-11-13
* @desc  WEB 初始化相关配置
*/
//@EnableWebMvc
//@ControllerAdvice
@Configuration
public class MyWebConfig extends WebConfig {

/*    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("*//**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX+"/templates/");
        //registry.addResourceHandler("/static*//**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX+"/static/");
       super.addResourceHandlers(registry);
    }*/

    /**
     * 视图控制器配置
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/login");  //setViewName("/index");
        super.addViewControllers(registry);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getAuthInterceptor())
                .excludePathPatterns("/easyui/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/images/**");
        super.addInterceptors(registry);
    }

    @Bean
    public AuthInterceptor getAuthInterceptor(){
        return new AuthInterceptor();
    }
}
